// +----------------------------------------------------------------------
// | xx [ xx赋能开发者，方便快捷开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.xxx.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed xx并不是自由软件，未经许可不能去掉xx相关版权
// +----------------------------------------------------------------------
// | Author: xx Team <xx@xx.com>
// +----------------------------------------------------------------------
// | Description:   标签
// +----------------------------------------------------------------------

import { defineStore } from "pinia";
import { SelfStorage } from "../securels";

export const useViewTagsStore = defineStore("sysKeepAlive", {
  state: () => {
    return {
      // 标签数据
      list: [],
    };
  },
  actions: {
    /**
     * @description: 添加缓存
     * @param {*} component
     */
    addKeepAliveName(component) {
      if (!this.list.includes(component)) {
        this.list.push(component);
      }
    },
    /**
     * @description: 删除缓存
     * @param {*} component
     */
    removeKeepAliveName(component) {
      this.list = this.list.filter((item) => item !== component);
    },
    /**
     * @description: 批量删除缓存
     * @param {*} tags
     */
    removeKeepAliveNames(tags) {
      const tagNames = new Set(tags.map((item) => item.name));
      this.list = this.list.filter((item) => tagNames.has(item));
    },
  },
  // 持久化
  persist: {
    key: "VIEW_TAGS",
    storage: SelfStorage,
  },
});
